package com.mvp.ui.dialog;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mvp.R;
import com.mvp.base.BaseDialog;

import java.util.ArrayList;
import java.util.List;


/**
 * 此底部弹出框为recycleview实现，请按照需求在此基础上封装所要显示的效果，
 * 如果需要添加itemdecoration 请参照在此基础上封装
 * Created by zhangyuncai on 2018/9/11.
 */
public class BottonDialog extends BaseDialog {

    TextView tvCancel;
    RecyclerView recyclerView;
    private final List<String> items = new ArrayList<>();
    ;
    private BottomVeticalSelectAdapter adapter;

    public BottonDialog(Context context) {
        super(context);
        items.add("拍照");
        items.add("打开相册");
        adapter = new BottomVeticalSelectAdapter(items);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.botton_dialog;
    }

    protected void initView() {
        tvCancel = (TextView) findViewById(R.id.tv_cancel);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
        dividerItemDecoration.setDrawable(ContextCompat.getDrawable(getContext(), R.drawable.divider_1dp));
        recyclerView = (RecyclerView) findViewById(R.id.rv_Data);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(adapter);
        recyclerView.scheduleLayoutAnimation();
        recyclerView.addItemDecoration(dividerItemDecoration);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                dismiss();
                if (callBack != null) {
                    callBack.callback(position);
                }
            }
        });
    }

    @Override
    protected void initListener() {

    }

    private static class BottomVeticalSelectAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
        public BottomVeticalSelectAdapter(@Nullable List<String> data) {
            super(R.layout.adapter_bottomvetical, data);
        }

        @Override
        protected void convert(BaseViewHolder helper, String item) {
            helper.setText(R.id.tv_bottomdialog_name, item);
        }
    }
}
